﻿/*
 * Logger.cs
 * 
 * Purpose:
 * Provides a simple logging utility to help with locating errors, exceptions, and general debugging.
 * 
 * Revision Log:
 * 08-SEP-12, C. Bush, First Draft.
 */

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;

namespace Air_Trafic_Control.Domain.Util
{
    public class Logger
    {
        private Type classType;
        private string className;

        /// <summary>
        /// Create a new Logger.
        /// </summary>
        /// <param name="classType">The type of the class this logger will be used in.</param>
        public Logger(Type classType)
        {
            this.classType = classType;
            this.className = classType.FullName;
        }

        /// <summary>
        /// Logs the error message to the console with the calling method and line number.
        /// </summary>
        /// <param name="message">The error message to display.</param>
        public void Error(string message)
        {
            StackTrace stack = new StackTrace(true);
            System.Console.WriteLine("ERROR [" + className + "." + stack.GetFrame(1).GetMethod().Name.Replace(".", "") + ":" + stack.GetFrame(1).GetFileLineNumber() + ":" + stack.GetFrame(1).GetFileColumnNumber() + "]: " + message);
        }

        /// <summary>
        /// Logs the info message to the console with the calling method and line number.
        /// </summary>
        /// <param name="message">The info message to display.</param>
        public void Info(string message)
        {
            StackTrace stack = new StackTrace(true);
            System.Console.WriteLine("INFO [" + className + "." + stack.GetFrame(1).GetMethod().Name.Replace(".", "") + ":" + stack.GetFrame(1).GetFileLineNumber() + ":" + stack.GetFrame(1).GetFileColumnNumber() + "]: " + message);
        }
    }
}
